package com.guigu.health.service.impl;

import com.guigu.health.dao.OrderMapper;
import com.guigu.health.pojo.Order;
import com.guigu.health.pojo.OrderExample;
import com.guigu.health.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName:OrderServiceImpl
 * @Description:预约业务实现类
 * @Author:longtao
 * @Date:2021/4/2
 * @Version:1.0
 */
@Service("orderService")
public class OrderServiceImpl implements OrderService {

    private OrderMapper orderMapper;
    @Autowired
    @Qualifier("orderMapper")
    public void setOrderMapper(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    @Override
    public boolean addOrder(Order order) {
        boolean flag=false;
        if (orderMapper.insert(order)>0){
            flag=true;
        }
        return flag;
    }

    @Override
    public boolean updateOrder(Order order, OrderExample example) {
        boolean flag=false;
        int i = orderMapper.updateByExampleSelective(order, example);
        if(i>0){
            flag=true;
        }
        return flag;
    }

    @Override
    public boolean deleteOrder(Integer id) {
        boolean flag=false;
        int i = orderMapper.deleteByPrimaryKey(id);
        if (i>0){
            flag=true;
        }
        return flag;
    }

    /**
     * 统一进七天的预约数
     * @param date
     * @return
     */
    @Override
    public List<Long> getCount(List<String> date) {
        List<Long> memberCount = new ArrayList<Long>();
        if (date!=null){
            for (String s : date) {
                long l = orderMapper.countOrder(s);
                memberCount.add(l);
            }
        }
        return memberCount;
    }

    @Override
    public long getTheNumberOfReserved(String date) {
        return orderMapper.countOrder2(date);
    }
}
